package net.hserver.oauth.controller;

import cn.hserver.plugin.web.annotation.Controller;
import cn.hserver.plugin.web.annotation.GET;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class OpenidConfigurationController {
    @GET("/.well-known/openid-configuration2")
    public Map<String, Object> getOpenidConfiguration2() {
        Map<String, Object> map = new HashMap<>();
        map.put("issuer", "http://127.0.0.1:8888");
        //https://gitee.com/oauth/token?grant_type=authorization_code&code={code}&client_id=cca9e59ff559e675f8f4ccbeaa5daf79679f596f5507ca78380b3bd1feb35689&redirect_uri=http%3A%2F%2F127.0.0.1%3A3000%2Fuser%2Foauth2%2Fgitea%2Fcallback&client_secret={client_secret}
        map.put("authorization_endpoint", "https://gitee.com/oauth/authorize");
        map.put("token_endpoint", "https://gitee.com/oauth2/token");
        map.put("userinfo_endpoint", "https://gitee.com/oauth2/userinfo");
        map.put("response_types_supported", List.of("code","id_token"));
        map.put("scope_supported", List.of("openid","profile","email","oidc"));
        map.put("grant_types_supported", List.of("authorization_code","implicit","refresh_token"));
        map.put("jwks_uri", "https://gitee.com/jwks.json");
        map.put("claims_supported", List.of("aud","exp","iat","iss","sub","name"));
//        "claims_supported": [
//        "aud",
//                "exp",
//                "iat",
//                "iss",
//                "sub",
//                "name",
//                "preferred_username",
//                "profile",
//                "picture",
//                "website",
//                "locale",
//                "updated_at",
//                "email",
//                "email_verified",
//                "groups"
//],
        return map;
    }

    @GET("/.well-known/openid-configuration")
    public Map<String, Object> getOpenidConfiguration() {
        Map<String, Object> map = new HashMap<>();
        map.put("issuer", "http://127.0.0.1:8888");
        map.put("authorization_endpoint", "http://127.0.0.1:8888/oauth2/authorize");
        map.put("token_endpoint", "http://127.0.0.1:8888/oauth2/token");
        map.put("userinfo_endpoint", "http://127.0.0.1:8888/oauth2/userinfo");
        map.put("response_types_supported", List.of("code","id_token"));
        map.put("scope_supported", List.of("openid","profile","email","oidc"));
        map.put("grant_types_supported", List.of("authorization_code","implicit","refresh_token"));
        map.put("jwks_uri", "http://127.0.0.1:8888/.well-known/jwks.json");
        map.put("claims_supported", List.of("aud","exp","iat","iss","sub","name"));
//        "claims_supported": [
//        "aud",
//                "exp",
//                "iat",
//                "iss",
//                "sub",
//                "name",
//                "preferred_username",
//                "profile",
//                "picture",
//                "website",
//                "locale",
//                "updated_at",
//                "email",
//                "email_verified",
//                "groups"
//],
        return map;
    }


//    @GET("/.well-known/jwks.json")
//    public Map<String, Object> jws() {
//        List<Map<String, Object>> data = new ArrayList<>();
//        Map<String, Object> map = new HashMap<>();
//        map.put("kty", "RSA");
//        map.put("kid", "222");
//        map.put("use", "sig");
//        map.put("alg", "RS256");
//        map.put("n", "0HWYic4Qp0eaJLVz71m96hCPOc-eI6JsXTwT1g_swALm8qGWWfgyTwE-OhBMRjDlw1ybOwVFl1VSG37PxcA8IfUuZgAhHSUQsJBgnKYeB9tg7EVMOuTE2XMpq_R4PthGFa5iQ-BMe-rTIPJ3k-ebn9ltT6ZZxR1PNud7Arr_VLnsKyaWboFXlAh849M4dtukebQo9U7PIBjbVc6XM3eTK971-__9Q8BP2Syf8tZcFKIpBf2HASabJbx9jWLqxRwLaecAiLq2sAgFSTKb5BVJtS7pAQUmpbf08X3yB9foGhIKvEL_MG8gHgEH41Odv75KzADrkZVE0hZnALhOaC9LIw");
//        map.put("e", "AQAB");
//        data.add(map);
//
//        Map<String, Object> map1 = new HashMap<>();
//        map1.put("keys",data);
//        return map1;
//    }
//
    @GET("/.well-known/jwks.json")
    public Map<String, Object> jws() {
        List<Map<String, Object>> data = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("kty", "RSA");
        map.put("kid", "123");
        map.put("use", "sig");
        map.put("alg", "RS256");
        map.put("n", "0HWYic4Qp0eaJLVz71m96hCPOc-eI6JsXTwT1g_swALm8qGWWfgyTwE-OhBMRjDlw1ybOwVFl1VSG37PxcA8IfUuZgAhHSUQsJBgnKYeB9tg7EVMOuTE2XMpq_R4PthGFa5iQ-BMe-rTIPJ3k-ebn9ltT6ZZxR1PNud7Arr_VLnsKyaWboFXlAh849M4dtukebQo9U7PIBjbVc6XM3eTK971-__9Q8BP2Syf8tZcFKIpBf2HASabJbx9jWLqxRwLaecAiLq2sAgFSTKb5BVJtS7pAQUmpbf08X3yB9foGhIKvEL_MG8gHgEH41Odv75KzADrkZVE0hZnALhOaC9LIw");
        map.put("e", "AQAB");
        data.add(map);

        Map<String, Object> map1 = new HashMap<>();
        map1.put("keys",data);
        return map1;
    }

}
